package com.xjcs.saplingplan.ui.fragment

import android.annotation.SuppressLint
import com.xjcs.saplingplan.adapter.CountdownTypeAdapter
import com.xjcs.saplingplan.base.BaseVbFragment
import com.xjcs.saplingplan.const.setSingleClick
import com.xjcs.saplingplan.databinding.FragmentCountdownBinding
import com.xjcs.saplingplan.dialog.CountdownTypePop
import com.xjcs.saplingplan.model.bean.countdown.CountdownTypeBean
import com.xjcs.saplingplan.ui.activity.countdown.CountdownCreateActivity
import com.xjcs.saplingplan.utils.DialogUtils

class CountdownFragment: BaseVbFragment<FragmentCountdownBinding>() {

    override fun getViewBinding(): FragmentCountdownBinding {
        return FragmentCountdownBinding.inflate(layoutInflater)
    }

    private var countdownAdapter: CountdownTypeAdapter? = null

    override fun initUi() {
        initView()
        initRecyclerView()
        getData()
    }

    private fun initView() {
    }

    private fun initRecyclerView() {
        val list = mutableListOf<CountdownTypeBean>()
        list.add(CountdownTypeBean(-1, "全部"))
        list.add(CountdownTypeBean(0, "倒数日"))
        list.add(CountdownTypeBean(1, "纪念日"))
        list.add(CountdownTypeBean(2, "生日"))
        list.add(CountdownTypeBean(3, "节日"))
        countdownAdapter = CountdownTypeAdapter(requireContext(), list)
        mBinding.recyclerViewType.adapter = countdownAdapter
    }

    private fun getData() {
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun registerObserver() {
    }

    override fun initListener() {
        mBinding.ivAdd.setSingleClick {
            showCountdownTypePop()
        }
    }

    private fun showCountdownTypePop() {
        DialogUtils.showAttachPop(requireContext(), outDismiss = true, showBg = true)
            .atView(mBinding.ivAdd)
            .asCustom(CountdownTypePop(requireContext()){ type ->
                CountdownCreateActivity.startActivity(requireContext(), type)
            })
            .show()
    }

}